package leetcode.view0406;

import leetcode.IDebug;
import leetcode.helper.tree.TreeNode;

public class Solution implements IDebug {
	
	TreeNode next;
	int val;

	public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {
		next = null;
		val = p.val;
		find(root);
		return next;
	}

	private void find(TreeNode root) {
		if (root == null) {
			return;
		}
		int cur = root.val;
		if (cur > val) {
			next = root;
			this.find(root.left);
		} else {
			this.find(root.right);
		}
	}



	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
